// Using FileSystemObject and Dir() function to copy all files form one directory to another

Public Function Copy_Files_Folder(ByRef strFrom_Path As String, ByRef strTo_Path As String)
    'Copy all the files in a directory to another'
    Dim FSO As FileSystemObject
    Dim strFile As String 'Used to store the files that are found

    On Error GoTo err_hndl
    
    'Simple check if the path is correct it hase to end with "\" else is added
    If Right$(strFrom_Path, 1) <> "\" Then strFrom_Path = strFrom_Path & "\"
    If Right$(strTo_Path, 1) <> "\" Then strTo_Path = strTo_Path & "\"
    
        
    'find the files with the extension as *.* for all files in the current path
    strFile = Dir(strFrom_Path & "*.*")
    'list all the file till dir return empty string
    Do While Len(strFile)
        Set FSO = New FileSystemObject
        With FSO
            'check if the new folder exist if not create new one
            If Not .FolderExists(strTo_Path) Then .CreateFolder (strTo_Path)
                .CopyFile strFrom_Path & strFile, strTo_Path & strFile 'copy the files in the new directory
        End With

        Set FSO = Nothing
        strFile = Dir          'send the next file to variable File
    Loop
    Exit Function
err_hndl:
    MsgBox "Error in Copy_Files_Folder()" & vbCrLf & Err.Number & ": " & Err.Description, vbCritical
End Function


Private Sub Command1_Click()
    'test button click
    Call Copy_Files_Folder(txtForm_Path.Text, txtTo_Path.Text)
End Sub